<?php

namespace App\Admin\Controllers;

use App\Models\DeviceList;
use App\Models\Engineering;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class DeviceListController extends AdminController
{
    protected $title = '考勤设备';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new DeviceList(), function (Grid $grid) {
            $grid->disableViewButton();
            $grid->column('id')->sortable();
            $grid->column('sn','设备号');
            $grid->column('engineering_name');
            $grid->column('morning','上午打卡有效时间限制');
            $grid->column('afternoon','下午打卡有效时间限制');
//            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new DeviceList(), function (Show $show) {
            $show->field('id');
            $show->field('mac');
            $show->field('engineering_name');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new DeviceList(), function (Form $form) {
//            $form->display('id');
            $form->text('sn');
            $form->select('engineering_name','所属工程')->options(function ($id) {
                return Engineering::where('engineering_name','<>','')->pluck('engineering_name', 'engineering_name');
            });

            $form->time('morning','上午打卡有效时间限制');
            $form->time('afternoon','下午打卡有效时间限制');

//            $form->display('created_at');
//            $form->display('updated_at');
        });
    }
}
